/**
 * 试剂耗材详情
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/6
 */
var self = id = memberInfo = '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	
	self = plus.webview.currentWebview();
	
	memberInfo = plus.storage.getItem('memberInfo');
	
	memberInfo = $.parseJSON(memberInfo);
	
	uid = memberInfo.aid;
	id = self.aid; 
	$('.demand').text(self.content)
	
	var data = plus.storage.getItem('fangan');
	
	data = $.parseJSON(data);
	
	$.each(data, function(k , v) {
		if(v.id == id){ 
			if(v.recommend != ''){
				$('.result').text(v.recommend.length + '条推荐方案');
				$.each(v.recommend, function(key , value) {
					console.log(JSON.stringify(value))
					var html =  '<div class="background-w table-view table-view-cell-3-15 padding-bottom-10 font-14 line-h-25 margin-bottom-1">';
						html += '<li class="overflow-h line-h-28"><div class="mui-pull-left mui-col-xs-6 ellipsis-1">'+value.title+'</div>';
						html += '<div class="mui-pull-left mui-col-xs-6 me-fb-inf-fa-btn overflow-h">';
						html += '<button type="button" class="background-zx color-white mui-btn "><i class="iconfont" style="vertical-align: middle;">&#xe611;</i><span class="mll" onclick="order('+value.business_id+' , \''+value.title+'\' , \''+value.classify+'\')">下单</span></button>';
						html += '<button type="button" class="background-zx color-white mui-btn "><i class="iconfont" style="vertical-align: middle;">&#xe622;</i><span class="mll" onclick="message('+value.business_id+' , '+value.tid+' , \''+value.title+'\')">留言</span></button>';
						html += '<button type="button" class="background-zx color-white mui-btn "><i class="iconfont" style="vertical-align: middle;" onclick="call('+value.phone+')">&#xe60f;</i><span class="mll">电话</span></button>';
						html += '</div><li class="color-zx-2 line-h-18 font-12"><span>周期：'+value.cycle+'</span>&emsp;&emsp;<span>报价'+value.offer+'</span></li>';
						html += '<li class="color-c margin-top-5"><span>'+value.details+'</span></li></div>';
					$('.lists').append(html);
				});
			}else{
				$('.result').text('暂无推荐方案');
			}
		}
		
	});
	
}
 
/**
 * 拨打电话
 * @param {Object} phone
 */
function call(phone){
	//拨打电话 
	if(!phone){
		toast('没有获取到手机号');return;
	}
	plus.nativeUI.confirm('温馨提示: 	确定要拨打'+phone+'吗？' , function(e){
		if(e.index == 0){
			plus.device.dial(phone , false);
		}
	} , '第三方咨询' , ['确定' , '取消'])
}

/**
 * 留言
 * @param {Object} id
 * @param {Object} tid
 * @param {Object} title
 */
function message(id , tid , title){
	plus.nativeUI.showWaiting('跳转中...');
	var ly = plus.webview.create('ly.html', 'ly', {}, {
		uid : memberInfo.aid, 
		nickname : memberInfo.nickname,
		aid : id,
		tid : tid,
		title : title
	}); 
	ly.addEventListener('loaded', function (){
		ly.show('pop-in');
		plus.nativeUI.closeWaiting();
	})	
}

/**
 * 下单
 * @param {Object} id
 * @param {Object} title
 * @param {Object} classify
 */
function order(id , title , classify){
	plus.nativeUI.showWaiting('跳转中...');
	var order_xd_inf = plus.webview.create('order-xd-inf.html', 'order_xd_inf', {}, {
		uid : memberInfo.aid, 
		nickname : memberInfo.nickname,
		aid : id,
		title : title,
		classify : classify
	}); 
	order_xd_inf.addEventListener('loaded', function (){
		order_xd_inf.show('pop-in');
		plus.nativeUI.closeWaiting();
	})	
}
